﻿using System;
using System.Web.UI.WebControls;

public partial class aspx_admin_teacher_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "Cancel")
        {
            Response.Redirect("view.aspx");
        }
    }

    protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        WebHelper.MessageBox.Show("更新成功!", "view.aspx");
    }

    protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        FileUpload fu = this.FormView1.FindControl("fu") as FileUpload;
        if (fu.HasFile)
        {
            try
            {
                Guid id = Guid.NewGuid();
                string filename = id.ToString() + System.IO.Path.GetExtension(fu.FileName);
                e.NewValues["虚目录"] = string.Format("~/images/teacher/small/{0}", filename);
                WebHelper.WebControls.UploadFile(
                         fu,
                         "~/images/teacher/small/",
                         new string[] { ".jpg", ".png", ".gif", ".jpeg", ".bmp" },
                         filename,
                         false,
                         int.MaxValue);
                WebHelper.FileAndDirectory.DeleteFile(e.OldValues["虚目录"] as string);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}